package com.yunduansing.core.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.yunduansing.core.commons.DbCommon;
import com.yunduansing.core.commons.DbCommon.Grid;
import com.yunduansing.core.dao.BaseDao;
import com.yunduansing.core.service.BaseService;
import com.yunduansing.core.utils.ResultUtil;

public class BaseServiceImpl<T> implements BaseService<T> {
	@Autowired
	private BaseDao<T> dao;

	public T getByKey(Object key) {
		return dao.getByKey(key);
	}

	public ResultUtil save(T entity) {
		return null;
	}

	public ResultUtil deleteByKeys(List<Object> keys) {
		try{
			return ResultUtil.init(dao.deleteByKeys(keys)>0);
		}catch(Exception e){
			return ResultUtil.init(e);
		}
	}

	public Object pagination(Grid grid, Object search) {
		DbCommon.Pager pager=new DbCommon.Pager();
		pager.setIndex(grid.getIndex());
		pager.setData(dao.pagination(grid, search));
		pager.setRows(dao.pageCount(search));
		return pager;
	}

}
